<template>
  <v-card>
      <v-flex xs12 sm10>
        <v-tree url="/goods/category/list"
                :isEdit="isEdit"
                :newNodeId="newNodeId"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                @handleClick="handleClick"
        />
      </v-flex>
  </v-card>
</template>

<script>
  export default {
    name: "category",
    data() {
      return {
        isEdit:true,
        newNodeId: -1
      }
    },
    methods: {
      handleAdd(node) {
        console.log("add .... ");
        this.$http.post("/goods/category/add" , this.$qs.stringify(node))
          .then((resp) => {
            this.newNodeId = resp.data.id;
            this.$message.success("添加成功");
          })
          .catch(() => this.$message.error("添加失败"));
      },
      handleEdit(id, name) {
        console.log("edit... id: " + id + ", name: " + name);
        this.$http.put("/goods/category/update", {params: {id:id, name:name}})
          .then( () => this.$message.success("修改成功"))
          .catch(() => this.$message.error("修改失败"));
      },
      handleDelete(node) {
        console.log("delete ... " + node.id);
        this.$http.delete("/goods/category/delete", this.$qs.stringify(node))
          .then(() => {this.$message.success("删除成功")})
          .catch(() => this.$message.error("删除失败"));
      },
      handleClick(node) {
        console.log(node)
      }
    }
  };
</script>

<style scoped>

</style>
